package listbyorder.access001_100.test97;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/6 10:07
 */
public class Solution1 {

    // 方法一： 暴力递归
    public boolean isInterleave(String s1, String s2, String s3) {
        if (s1.equals("")) return s2.equals(s3);
        if (s2.equals("")) return s1.equals(s3);
        if (s1.length() + s2.length() != s3.length()) return false;
        return getAns(s1, 0, s1.length(), s2, 0, s2.length(), s3, 0, s3.length());
    }

    private boolean getAns(String s1, int c1, int l1, String s2, int c2, int l2, String s3, int c3, int l3) {
        if (c1 == l1) return s2.substring(c2, l2).equals(s3.substring(c3, l3));
        if (c2 == l2) return s1.substring(c1, l1).equals(s3.substring(c3, l3));
        if (s1.charAt(c1) == s3.charAt(c3) && getAns(s1, c1 + 1, l1, s2, c2, l2, s3, c3 + 1, l3)) {
            return true;
        }
        if (s2.charAt(c2) == s3.charAt(c3) && getAns(s1, c1, l1, s2, c2 + 1, l2, s3, c3 + 1, l3)) {
            return true;
        }
        return false;
    }


}
